package com.hjf.lambda;

import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntConsumer;
import java.util.function.IntPredicate;

public class Lambda01 {

    public static void main(String[] args) {
        int i = calculateNum(Integer::sum);
        System.out.println(i);

        printNum(num->num%2==0);

        Integer integer = typeConvert(Integer::parseInt);
        System.out.println(integer);

        foreachArr(System.out::print);
    }

    public static void foreachArr(IntConsumer consumer){
        int[] arr =  {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            consumer.accept(i);
        }
    }

    public static <R> R typeConvert(Function<String,R> function){
        String str = "123456";
        return function.apply(str);
    }


    public static void printNum(IntPredicate predicate){
        int[] arr =  {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            if(predicate.test(i)){
                System.out.println(i);
            }
        }

    }

    public static int calculateNum(IntBinaryOperator operator){
        int a = 10;
        int b = 20;
        return operator.applyAsInt(a,b);
    }



}
